package com.jason.quectel;

import com.jason.wan.ProtectedDemo;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws EmptyMoneyException {
        //try {
        //    String result = readFile("./src/test.txt");
        //    System.out.println(result);
        //} catch (IOException e) {
        //    e.printStackTrace();
        //}
        //try {
        //    writeFile("你好，quectel", "./src/quectel.txt");
        //} catch (IOException e) {
        //    e.printStackTrace();
        //}
        //throw new EmptyMoneyException("你的余额不足咯");

        //Animal animal = new Dog();
        //animal.shout();
        //animal.eat();

        //AnimalBehavior animalBehavior = new Dog();
        //animalBehavior.shout();
        //animalBehavior.eat();
        //sort(new String[]{"a", "b", "c"});
        sort(new Float[]{1f, 2f, 3f});

        //ArrayList list = new ArrayList();
        //list.add(1);
        //list.add(2);
        //list.add(3);
        //list.add("4");
        //list.add(new Integer(3));
        //System.out.println(list);

        //List list = new ArrayList<String>();
        //list.add("你好");
        //list.add("quectel");
        //print(list);

        ProtectedDemo protectedDemo = new ProtectedDemo();
        protectedDemo.function2();

        List<Cat> list = new ArrayList<>();
        Cat cat = new Cat("球球", 1);
        list.add(cat);
    }

    //private static void sort(int[] array) {
    //
    //}
    //
    //private static void sort(long[] array) {
    //
    //}
    //
    //private static void sort(String[] array) {
    //
    //}

    private static <E extends Number> void sort(E[] array) {
        for (E e : array) {
            if (e instanceof Integer) {
                System.out.print("是整型数据");
            } else {
                System.out.print("不是整型数据");
            }
            System.out.println(e.toString());
        }
    }

    private static void print(List<? extends Number> list) {
        for (Number number : list) {
            System.out.println(number.toString());
        }
    }

    private static void readFromConsole() {
        Scanner scanner = new Scanner(System.in);
        String content = null;
        do {
            content = scanner.next();
            System.out.println(content);
        } while (!"q".equals(content));
    }

    private static String readFile(String filePath) throws IOException {
        File file = new File(filePath);
        FileInputStream fileInputStream = new FileInputStream(file);
        InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, StandardCharsets.UTF_8);
        StringBuffer stringBuffer = new StringBuffer();
        int result = 0;
        while (result != -1) {
            result = inputStreamReader.read();
            stringBuffer.append(((char) result));
        }
        return stringBuffer.toString();
    }

    private static void writeFile(String content, String filePath) throws IOException {
        File file = new File(filePath);
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        fileOutputStream.write(content.getBytes(StandardCharsets.UTF_8));
    }
}
